package workSheets;

import java.util.ArrayList;
import java.util.List;
import java.util.Random;
import java.util.Scanner;

public class workSheet7 {
    public static void main (String[] args) {
        //User input animal name and animal type
        List<animal> all = new ArrayList<> ();
        while (true) {
            Scanner scan = new Scanner (System.in);
            //User input animal name and animal type
            System.out.println ("input animal's type and name split by ','");
            System.out.println ("input quit to exit");
            String s = scan.nextLine ();
            String[] split = s.split (",");
            if (s.equalsIgnoreCase ("quit")) {
                System.out.println ("GOOD BYE");
                System.exit (0);
            } else if (split.length != 2) {

            } else {
                all.add (new animal (split[0], split[1]));
                //User chooses whether to continue to input animal information
                System.out.println ("Do you want to continue output(Y/N)");
                String check = scan.nextLine ();
                if (check.equalsIgnoreCase ("Y")) {

                } else {
                    break;
                }
            }
        }
        System.out.println (all.get (0));
        new Zoo (all.get (0)).eat ();
    }
}

@SuppressWarnings ("all")
class Zoo {
    private animal animal;
    private int food;
    int i = 0;

    /**
     * @param animal Zoo animals
     */
    public Zoo (animal animal) {
        this.animal = animal;
    }

    public void eat () {
        //When animals are hungry, the zoo may  feed
        if (animal.isFull ()) {
            System.out.println ("I am full");
        } else {
            //Zoo feeding procedure
            while (true) {
                int i = new Random ().nextInt (9);
                food = animal.getAmontoffood () + i;
                if (food >= 10) {
                    System.out.println ("The zoo send   " + i + "   food");
                    System.out.println ("I am full,thanks");
                    break;
                } else {
                    animal.setAmontoffood (food);
                    food = animal.getAmontoffood ();
                    System.out.println ("The zoo send   " + i + "   food");
                    System.out.println ("I am still hungry");
                }
            }
        }
    }
}

@SuppressWarnings ("all")
class animal {
    private String type;
    private String name;
    private int amontoffood;

    /**
     * @param type Animal Type
     * @param name Animal Name
     */
    public animal (String type, String name) {
        this.type = type;
        this.name = name;
        //State of random animal food consumption
        amontoffood = new Random ().nextInt (9) + 1;
    }

    public String getType () {
        return type;
    }

    public void setType (String type) {
        this.type = type;
    }

    public String getName () {
        return name;
    }

    public void setName (String name) {
        this.name = name;
    }

    public int getAmontoffood () {
        return amontoffood;
    }

    public void setAmontoffood (int amontoffood) {
        this.amontoffood = amontoffood;
    }

    public boolean isFull () {
        if (amontoffood == 0) {
            return false;
        } else if (amontoffood == 10) {
            return true;
        } else {
            return false;
        }
    }

    //Animal information output
    @Override
    public String toString () {
        return "animal{" +
                "type='" + type + '\'' +
                ", name='" + name + '\'' +
                ", amontoffood=" + amontoffood +
                '}';
    }
}
